Skip to content

Reimplement UnitsState::prepareProjectileTarget at 100%, from gynt's text on main (one header line each in two files) - #540

Open
kotijekriv wants to merge 2 commits into
sourcehold:mainfrom
kotijekriv:reimpl/units-A-unitsstate1-header-100
Open

kotijekriv wants to merge 2 commits into
sourcehold:mainfrom
kotijekriv:reimpl/units-A-unitsstate1-header-100

Conversation

@kotijekriv

Copy link
Copy Markdown
Contributor

UnitsState::prepareProjectileTarget (0x0053CBD0) from 85.7% / 79.2% (reccmp raw / normalised; gynt's text, on main since #238) to 100.0% / 100.0%, with OPENSHC_FUNCTION_VISIBILITY_UNITS off and on.

Header change

int prepareProjectileTarget(...) becomes void in UnitsState.hpp and UnitsState.func.hpp (a commit of its own). In UnitsState.hpp the same line also names the third parameter leadDistanceUnk, as the definition does. Main's declaration check fails and labels this PR until main has the two lines.

  • The original leaves something different in eax on each path: the unit type less 22, which is the switch index (0x0053CDD3), a quotient, or the 16-bit value it just stored.
  • None of the seventeen calls on main reads a result.
  • The code matches with void only. With int the leftover values have to be named and returned, and the scatter and the random number swap registers.

What matched it

  • void: the returned values go, and with them the comment that they mean nothing (quick_diff 0.8566 -> 0.9928).
  • The height's random adjustment is written on the field, += / -= in two arms, instead of through an unsigned copy (1.0000).
  • The three kinds of scatter are one if / else-if chain instead of two early returns: the same listing.
  • The order of the tests and every constant are gynt's.

Kept as it is

  • gynt's todo:fixme:ucp: note about targets with a negative height.
  • _archerScatter is never read, but its stores keep the archers' entries in both jump tables. Without them both tables start at the catapult (0.9857 in quick_diff).
  • The target's position is stored in both arms: the three stores once above the if give 0.9162.

Measured

Setup: the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie. All builds of this branch were made on main 4591b6f. It is cut from main 0cea04d, which adds six status lines (#538) and a tools script: nothing that is compiled.

Other PRs

#539 is ours and open: the six other UnitsState functions of the same round, whose full and final small builds above were made together with this branch. It shares only the status file with this one, in other lines.

#536 is ours and open; it shares only the status file with this one, in other lines, and calls prepareProjectileTarget nowhere.

🤖 Generated with Claude Code

kotijekriv and others added 2 commits December 2, 2026 02:52
prepareProjectileTarget 0x0053CBD0 is `void`: the header has `int`, from Ghidra.

The original leaves something different in eax on each path: the unit type less 22 (the switch index, 0x0053CDD3), a
quotient, the 16-bit value it just stored. None of the seventeen calls on main reads a result, and the code
matches with `void` only (the next commit): with `int`, the values have to be named and held, and scatter and the random
number swap registers (85.7% / 79.2%).

UnitsState.hpp and UnitsState.func.hpp, one line each. The declaration in UnitsState.hpp also names the third parameter
leadDistanceUnk, as the definition does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
UnitsState::prepareProjectileTarget from 85.7% / 79.2% (gynt's text, on main since sourcehold#238) to 100%.

With the function `void` (the commit before), the returned values go (quick_diff 0.8566 -> 0.9928). The random
adjustment of the target's height is written on the field itself, `+=` / `-=` in two arms, instead of through an
unsigned copy (1.0000), and the three kinds of scatter are one if / else-if chain (the same listing). The random numbers
that fed the returned quotients are passed straight on, the copy of the target's fixedRng is an int, and _scatter and
_adjustment start at 0 (the same object code). _archerScatter is never read but stays: without it the archer cases go
and both jump tables start at the catapult (quick_diff 0.9857). The target's position is stored in both arms, as before:
once above the if reads 0.9162. The order of the tests and every constant are gynt's (e595955 81.5%, 0c20880
85.75%).

Measured with real builds of this branch's tree on main 4591b6f (bundled MSVC1400-SP1, function and data resolvers on
locally, reccmp raw / normalised): 100.0 / 100.0 in a small build with OPENSHC_FUNCTION_VISIBILITY_UNITS off, in one
with it on, and in a full build with it off (of this branch merged with the one for six other UnitsState functions).
Passing the random numbers straight on, the int copy of fixedRng, the first values of _scatter and _adjustment and the
two comments came after those builds. A small build with it off of the final text (this branch merged with the one for
six other UnitsState functions, 550 files, 560 functions) reads every function as the earlier small build with it off
did.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

declaration/type change This requires changes to the generated/exported types or definitions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant